package Demo;

import java.util.*;

public class Demo80 {
    public static void main(String[] args) {
        Set<Integer> set=new HashSet<> ();
        Map<student, Integer> m = new HashMap<>();
        m.put(new student("laomai", 18), 1);
        m.put(new student("wang", 20), 1);
        m.put(new student("qq", 20), 1);
        m.put(new student("qq", 19), 1);
        System.out.println(m.get(new student("laomai", 18)));
        Set<Map.Entry<student,Integer>> s=m.entrySet();
        for (Map.Entry<student,Integer> ss:s){
            System.out.println(ss);
        }
        Iterator<Map.Entry<student,Integer>> iter=s.iterator();
        while (iter.hasNext()){
            Map.Entry<student, Integer> next = iter.next();
            System.out.println(next);
        }
        System.out.println(m);
    }
}

class student implements Comparable<student> {
    private String name;
    private int age;

    public student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(student student) {
        if (this.age > student.age) {
            return 1;
        }
        if (this.age < student.age) {
            return -1;
        } else {
            return this.name.compareTo(student.name);
        }
    }

    @Override
    public String toString() {
        return
                name + "*" + age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof student)) return false;
        student student = (student) o;
        return age == student.age &&
                name.equals(student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
